<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'regDataSource.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script src='<%=basePath %>/dwr/interface/SystemService.js'></script>
	<script src='<%=basePath %>/dwr/engine.js'></script>
	<script type="text/javascript" src="<%=basePath%>/js/jquery.js"></script>
	<script type="text/javascript" src='<%=basePath %>/js/jquery.blockUI.js'></script>
	<style type="text/css">
		 body{
		 	font: normal  auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
		    color: #4f6b72; 
		    background: #EEF2FB; 
		 }
		 label {
				font-size: 14px;
				color: #486783;
				
				margin-bottom: 10px;
				font-weight: bold;
				letter-spacing: 2px;
				text-transform: uppercase;
			}
			
		.btn{
		    width: 100px;
		    color: #486783;
		    text-transform: uppercase;
		    text-shadow: #fff 1px 1px;
		    border-top: 1px solid #486783;
		    margin-top: 10px;
		}
		
		.btn {
		    width: 100px;
		    color: #486783;
		    text-transform: uppercase;
		    text-shadow: #fff 1px 1px;
		    border-top: 1px solid #B8C1D0;
		    border-left: 1px solid #B8C1D0;
		    margin-top: 10px;
		 
		    /*** Adding CSS3 Gradients ***/
		    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F5F9), to(#B7C0CF));
		    background:  -moz-linear-gradient(19% 75% 90deg,#F4F5F9, #B7C0CF);
		}
	</style>
	
	<script type="text/javascript">
		function showBlock(id) {
			$(id).block({message:"<h3>Loading</h3>", css:{border:"2px solid black"}});
		}
		function reg() {
			var dbName = $("#dbName").attr("value");
			if(!dbName || dbName=="") {
				alert("请输入数据库名称");
				return ;
			}	
			
			var ds_type = $("#dsType").attr("value") ;
			if(!ds_type||ds_type==""||ds_type=="-1") {
				alert("请选择数据源类型");
				return ;
			}
					
			var ds_ip = $("#dsIp").attr("value") ;
			if(!ds_ip||ds_ip=="") {
				alert("请输入数据源IP地址");
				return ;
			}
			
			var ds_port = $("#dsPort").attr("value") ;
			if(!ds_port||ds_port=="") {
				alert("请输入数据源端口地址");
				return ;
			}
			
			var ds_user = $("#dsUser").attr("value") ;
			if(!ds_user||ds_user=="") {
				alert("请输入数据源登陆用户");
				return ;
			}
			
			var ds_pass = $("#dsPass").attr("value") ;
			if(!ds_pass ||  ds_pass=="") {
				alert("请输入数据源登陆密码");
				return ;
			}
			
			showBlock("body") ;
			var str = '{"dataSourceIp":"'+ds_ip+'","databaseName":"'+dbName+'","databaseType":"'+ds_type+'","driverClass":"'+null+'","password":"'+ds_pass
						+'","port":'+ds_port+',"username":"'+ds_user+'","regeUsername":"${sessionScope.user}"}';
	
			SystemService.registDataSource(str,function(data){
				$("body").unblock();
　　　　　　　　　　setTimeout(function(){
					alert(data);
				},500);
			}) ;
		}
	</script>
  </head>
  
  <body>
  		<h3 style="margin-top: 15px;" align="center">数据源注册</h3>
  		<hr>
  		<div style="margin-left: auto;margin-right: auto;text-align: center;">
  			<form style="margin: auto;">
	  			<label>数据库名称</label>
	  				<input type="text" name="db_name" id="dbName"/><br>
	  			<label>数据源类型</label>
	  				<select style="width: 155px;" name="ds_type" id="dsType">
	  					<option value="-1">----请选择---</option>
	  					<option value="ORACLE">Oracle</option>
	  					<option value="MSSQL2005">Sql Server 2005</option>
	  					<option value="MSSQL2000">Sql Server 2000</option>
	  				</select><br>
	  			<label>数据源地址</label>
	  				<input type="text" name="ds_ip" id="dsIp" /><br>
	  			<label>数据源端口</label>
	  				<input type="text" name="ds_port" id="dsPort"/><br>
	  			<label>登陆&nbsp;&nbsp;用户</label>
	  				<input type="text" name="ds_user" id="dsUser"/><br>
	  			<label>登陆&nbsp;&nbsp;密码</label>
	  				<input type="text" name="ds_pass" id="dsPass"/><br>
	  			<input type="button" value="注册" class="btn" onclick="reg()">
  			</form>
  		</div>
  </body>
</html>
